package com.project.study.farming.base.controller;

import com.project.study.farming.base.entity.dto.AuditCropsDto;
import com.project.study.farming.base.entity.dto.AuditMedicineDto;
import com.project.study.farming.base.entity.po.PlantDetailPo;
import com.project.study.farming.base.service.MainPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * 用户
 * @since 2020-04-25
 */
@Controller
@RequestMapping
public class MainPageController {

    @Autowired
    private MainPageService mainPageService;

    @GetMapping("initUser")
    public ModelAndView initUser(){
        return this.mainPageService.initUser();
    }

    /**
     * 跳转用户主页
     * @param pageNum 页码
     * @return 主页信息
     */
    @GetMapping("search")
    public ModelAndView getCrops(@RequestParam(value = "pageNum", required = false) Integer pageNum){
        return this.mainPageService.searchMain(pageNum);
    }

    /**
     * 用户申请植物
     * @param dto 申请内容
     * @return 主页信息
     */
    @PostMapping("auditCrops")
    public ModelAndView auditCrops(AuditCropsDto dto){
        return this.mainPageService.auditCrops(dto);
    }

    /**
     * 我的申请页
     * @param pageNum 当前页
     * @param auditStatus 审批状态
     * @param cropId 植物id
     * @param type 种类
     * @return 我的申请页
     */
    @GetMapping("servicePage")
    public ModelAndView servicePage(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                    @RequestParam(value = "auditStatus", required = false) Integer auditStatus,
                                    @RequestParam(value = "cropId", required = false) Integer cropId,
                                    @RequestParam(value = "type", required = false) Integer type){
        return this.mainPageService.servicePage(pageNum, auditStatus, cropId, type);
    }

    /**
     * 通知公告页
     * @param pageNum 当前页
     * @return 通知公告页
     */
    @GetMapping("messageConsumer")
    public ModelAndView messagePage(@RequestParam(value = "pageNum", required = false) Integer pageNum){
        return this.mainPageService.messagePage(pageNum);
    }

    /**
     * 农作物监控页
     * @param pageNum 当前页
     * @return 农作物监控页
     */
    @GetMapping("plantPage")
    public ModelAndView plantPage(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                  @RequestParam(value = "cropId", required = false) Integer cropId,
                                  @RequestParam(value = "plantStatus", required = false) Integer plantStatus){
        return this.mainPageService.plantPage(pageNum, cropId, plantStatus);
}

    /**
     * 种植
     * @param id 种植审批id
     * @return 农作物监控页
     */
    @GetMapping("doPlant")
    public ModelAndView doPlant(@RequestParam("id") Integer id, @RequestParam("pageNum") Integer pageNum){
        return this.mainPageService.doPlant(id, pageNum);
    }

    /**
     * 种植详情
     * @param id 种植id
     * @param pageNum 当前页
     * @return 详情页
     */
    @GetMapping("plantDetail")
    public ModelAndView plantDetail(@RequestParam("id") Integer id, @RequestParam("pageNum") Integer pageNum){
        return this.mainPageService.plantDetail(id, pageNum);
    }

    /**
     * 保存种植的虫害信息
     * @param detailPo 种植的虫害信息
     * @return 农作物监控页
     */
    @GetMapping("savePlantDetail")
    public ModelAndView savePlantDetail(PlantDetailPo detailPo){
        return this.mainPageService.savePlantDetail(detailPo);
    }

    /**
     * 农药监控页
     * @param pageNum 当前页
     * @return 农药监控页
     */
    @GetMapping("controlPage")
    public ModelAndView controlPage(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                    @RequestParam(value = "cropId", required = false) Integer cropId,
                                    @RequestParam(value = "areaId", required = false) Integer areaId){
        return this.mainPageService.controlPage(pageNum, cropId, areaId);
    }

    /**
     * 删除农药记录
     * @param id 农药id
     * @param pageNum 当前页
     * @return 农药监控页
     */
    @GetMapping("deleteControl")
    public ModelAndView deleteControl(@RequestParam("id") Integer id, @RequestParam("pageNum") Integer pageNum){
        return this.mainPageService.deleteControl(id, pageNum);
    }

    /**
     * 申请农药页面
     * @param id 种植id
     * @return 申请农药页面
     */
    @GetMapping("auditMedicine")
    public ModelAndView auditMedicine(@RequestParam("id") Integer id){
        return this.mainPageService.auditMedicine(id);
    }

    /**
     * 申请农药
     * @param dto 申请信息
     * @return 监控页面
     */
    @GetMapping("saveAuditMedicine")
    public ModelAndView saveAuditMedicine(AuditMedicineDto dto){
        return this.mainPageService.saveAuditMedicine(dto);
    }
}
